package com.example.demo.msg.netty.common;/**
 * Created by kete on 2018-08-13.
 */

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.msgpack.MessagePack;

import java.util.List;

/**
 * 作者：kete
 * 创建时间：2018-08-13 11:47
 * 功能描述：
 *
 * 版本：
 */
public class MsgPackDecode extends MessageToMessageDecoder<ByteBuf> {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        final int length = byteBuf.readableBytes();

        final byte[] array = new byte[length];

        byteBuf.getBytes(byteBuf.readerIndex(),array,0,length);

        list.add(new MessagePack().read(array,Imessage.class));
    }
}
